<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="试卷id" prop="examPaperId">
        <el-input
          v-model="queryParams.examPaperId"
          placeholder="请输入试卷id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考生用户ID" prop="studentId">
        <el-input
          v-model="queryParams.studentId"
          placeholder="请输入考生用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培训班id" prop="trainingClassId">
        <el-input
          v-model="queryParams.trainingClassId"
          placeholder="请输入培训班id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培训班" prop="trainingClassName">
        <el-input
          v-model="queryParams.trainingClassName"
          placeholder="请输入培训班"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培训项目id" prop="trainingProjectId">
        <el-input
          v-model="queryParams.trainingProjectId"
          placeholder="请输入培训项目id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培训项目名称" prop="trainingProjectName">
        <el-input
          v-model="queryParams.trainingProjectName"
          placeholder="请输入培训项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试编号" prop="examNumber">
        <el-input
          v-model="queryParams.examNumber"
          placeholder="请输入考试编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试开始时间" prop="examStartTime">
        <el-date-picker clearable
          v-model="queryParams.examStartTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择考试开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="考试结束时间" prop="examEndTime">
        <el-date-picker clearable
          v-model="queryParams.examEndTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择考试结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="实际考试时长(分钟)" prop="actualDuration">
        <el-input
          v-model="queryParams.actualDuration"
          placeholder="请输入实际考试时长(分钟)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试总分" prop="totalScore">
        <el-input
          v-model="queryParams.totalScore"
          placeholder="请输入考试总分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="理论成绩" prop="theoryResult">
        <el-input
          v-model="queryParams.theoryResult"
          placeholder="请输入理论成绩"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实操成绩" prop="practicalResult">
        <el-input
          v-model="queryParams.practicalResult"
          placeholder="请输入实操成绩"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="补考成绩" prop="makeUpResult">
        <el-input
          v-model="queryParams.makeUpResult"
          placeholder="请输入补考成绩"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试结果" prop="examResult">
        <el-input
          v-model="queryParams.examResult"
          placeholder="请输入考试结果"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试次数" prop="examFrequency">
        <el-input
          v-model="queryParams.examFrequency"
          placeholder="请输入考试次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="补考标记" prop="makeUpMark">
        <el-input
          v-model="queryParams.makeUpMark"
          placeholder="请输入补考标记"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电子证书" prop="electronicCertificate">
        <el-input
          v-model="queryParams.electronicCertificate"
          placeholder="请输入电子证书"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否可二次考试申报" prop="isSecondExam">
        <el-input
          v-model="queryParams.isSecondExam"
          placeholder="请输入是否可二次考试申报"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试终端IP地址" prop="examIp">
        <el-input
          v-model="queryParams.examIp"
          placeholder="请输入考试终端IP地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试终端坐标" prop="examCoordinates">
        <el-input
          v-model="queryParams.examCoordinates"
          placeholder="请输入考试终端坐标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备信息" prop="deviceInfo">
        <el-input
          v-model="queryParams.deviceInfo"
          placeholder="请输入设备信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="examRecordRemark">
        <el-input
          v-model="queryParams.examRecordRemark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['examination:examRecordSpecial:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['examination:examRecordSpecial:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['examination:examRecordSpecial:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['examination:examRecordSpecial:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="examRecordSpecialList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="考试记录ID" align="center" prop="examRecordId" />
      <el-table-column label="试卷id" align="center" prop="examPaperId" />
      <el-table-column label="考生用户ID" align="center" prop="studentId" />
      <el-table-column label="培训班id" align="center" prop="trainingClassId" />
      <el-table-column label="培训班" align="center" prop="trainingClassName" />
      <el-table-column label="培训项目id" align="center" prop="trainingProjectId" />
      <el-table-column label="培训项目名称" align="center" prop="trainingProjectName" />
      <el-table-column label="考试编号" align="center" prop="examNumber" />
      <el-table-column label="考试开始时间" align="center" prop="examStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.examStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="考试结束时间" align="center" prop="examEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.examEndTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际考试时长(分钟)" align="center" prop="actualDuration" />
      <el-table-column label="考试总分" align="center" prop="totalScore" />
      <el-table-column label="理论成绩" align="center" prop="theoryResult" />
      <el-table-column label="实操成绩" align="center" prop="practicalResult" />
      <el-table-column label="补考成绩" align="center" prop="makeUpResult" />
      <el-table-column label="考试结果" align="center" prop="examResult" />
      <el-table-column label="考试次数" align="center" prop="examFrequency" />
      <el-table-column label="补考标记" align="center" prop="makeUpMark" />
      <el-table-column label="电子证书" align="center" prop="electronicCertificate" />
      <el-table-column label="补考情况" align="center" prop="makeUpStatus" />
      <el-table-column label="是否可二次考试申报" align="center" prop="isSecondExam" />
      <el-table-column label="考试状态" align="center" prop="examStatus" />
      <el-table-column label="提交类型" align="center" prop="submitType" />
      <el-table-column label="考试终端IP地址" align="center" prop="examIp" />
      <el-table-column label="考试终端坐标" align="center" prop="examCoordinates" />
      <el-table-column label="设备信息" align="center" prop="deviceInfo" />
      <el-table-column label="备注" align="center" prop="examRecordRemark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['examination:examRecordSpecial:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['examination:examRecordSpecial:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改考试记录-特种设备对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="试卷id" prop="examPaperId">
          <el-input v-model="form.examPaperId" placeholder="请输入试卷id" />
        </el-form-item>
        <el-form-item label="考生用户ID" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入考生用户ID" />
        </el-form-item>
        <el-form-item label="培训班id" prop="trainingClassId">
          <el-input v-model="form.trainingClassId" placeholder="请输入培训班id" />
        </el-form-item>
        <el-form-item label="培训班" prop="trainingClassName">
          <el-input v-model="form.trainingClassName" placeholder="请输入培训班" />
        </el-form-item>
        <el-form-item label="培训项目id" prop="trainingProjectId">
          <el-input v-model="form.trainingProjectId" placeholder="请输入培训项目id" />
        </el-form-item>
        <el-form-item label="培训项目名称" prop="trainingProjectName">
          <el-input v-model="form.trainingProjectName" placeholder="请输入培训项目名称" />
        </el-form-item>
        <el-form-item label="考试编号" prop="examNumber">
          <el-input v-model="form.examNumber" placeholder="请输入考试编号" />
        </el-form-item>
        <el-form-item label="考试开始时间" prop="examStartTime">
          <el-date-picker clearable
            v-model="form.examStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择考试开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="考试结束时间" prop="examEndTime">
          <el-date-picker clearable
            v-model="form.examEndTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择考试结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="实际考试时长(分钟)" prop="actualDuration">
          <el-input v-model="form.actualDuration" placeholder="请输入实际考试时长(分钟)" />
        </el-form-item>
        <el-form-item label="考试总分" prop="totalScore">
          <el-input v-model="form.totalScore" placeholder="请输入考试总分" />
        </el-form-item>
        <el-form-item label="理论成绩" prop="theoryResult">
          <el-input v-model="form.theoryResult" placeholder="请输入理论成绩" />
        </el-form-item>
        <el-form-item label="实操成绩" prop="practicalResult">
          <el-input v-model="form.practicalResult" placeholder="请输入实操成绩" />
        </el-form-item>
        <el-form-item label="补考成绩" prop="makeUpResult">
          <el-input v-model="form.makeUpResult" placeholder="请输入补考成绩" />
        </el-form-item>
        <el-form-item label="考试结果" prop="examResult">
          <el-input v-model="form.examResult" placeholder="请输入考试结果" />
        </el-form-item>
        <el-form-item label="考试次数" prop="examFrequency">
          <el-input v-model="form.examFrequency" placeholder="请输入考试次数" />
        </el-form-item>
        <el-form-item label="补考标记" prop="makeUpMark">
          <el-input v-model="form.makeUpMark" placeholder="请输入补考标记" />
        </el-form-item>
        <el-form-item label="电子证书" prop="electronicCertificate">
          <el-input v-model="form.electronicCertificate" placeholder="请输入电子证书" />
        </el-form-item>
        <el-form-item label="是否可二次考试申报" prop="isSecondExam">
          <el-input v-model="form.isSecondExam" placeholder="请输入是否可二次考试申报" />
        </el-form-item>
        <el-form-item label="考试终端IP地址" prop="examIp">
          <el-input v-model="form.examIp" placeholder="请输入考试终端IP地址" />
        </el-form-item>
        <el-form-item label="考试终端坐标" prop="examCoordinates">
          <el-input v-model="form.examCoordinates" placeholder="请输入考试终端坐标" />
        </el-form-item>
        <el-form-item label="设备信息" prop="deviceInfo">
          <el-input v-model="form.deviceInfo" placeholder="请输入设备信息" />
        </el-form-item>
        <el-form-item label="备注" prop="examRecordRemark">
          <el-input v-model="form.examRecordRemark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="是否删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入是否删除" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listExamRecordSpecial, getExamRecordSpecial, delExamRecordSpecial, addExamRecordSpecial, updateExamRecordSpecial } from "@/api/examination/examRecordSpecial"

export default {
  name: "ExamRecordSpecial",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考试记录-特种设备表格数据
      examRecordSpecialList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        examPaperId: null,
        studentId: null,
        trainingClassId: null,
        trainingClassName: null,
        trainingProjectId: null,
        trainingProjectName: null,
        examNumber: null,
        examStartTime: null,
        examEndTime: null,
        actualDuration: null,
        totalScore: null,
        theoryResult: null,
        practicalResult: null,
        makeUpResult: null,
        examResult: null,
        examFrequency: null,
        makeUpMark: null,
        electronicCertificate: null,
        makeUpStatus: null,
        isSecondExam: null,
        examStatus: null,
        submitType: null,
        examIp: null,
        examCoordinates: null,
        deviceInfo: null,
        examRecordRemark: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询考试记录-特种设备列表 */
    getList() {
      this.loading = true
      listExamRecordSpecial(this.queryParams).then(response => {
        this.examRecordSpecialList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        examRecordId: null,
        examPaperId: null,
        studentId: null,
        trainingClassId: null,
        trainingClassName: null,
        trainingProjectId: null,
        trainingProjectName: null,
        examNumber: null,
        examStartTime: null,
        examEndTime: null,
        actualDuration: null,
        totalScore: null,
        theoryResult: null,
        practicalResult: null,
        makeUpResult: null,
        examResult: null,
        examFrequency: null,
        makeUpMark: null,
        electronicCertificate: null,
        makeUpStatus: null,
        isSecondExam: null,
        examStatus: null,
        submitType: null,
        examIp: null,
        examCoordinates: null,
        deviceInfo: null,
        examRecordRemark: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        exampleOne: null,
        exampleTwo: null,
        exampleThree: null,
        exampleFour: null,
        exampleFive: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.examRecordId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加考试记录-特种设备"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const examRecordId = row.examRecordId || this.ids
      getExamRecordSpecial(examRecordId).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改考试记录-特种设备"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.examRecordId != null) {
            updateExamRecordSpecial(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addExamRecordSpecial(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const examRecordIds = row.examRecordId || this.ids
      this.$modal.confirm('是否确认删除考试记录-特种设备编号为"' + examRecordIds + '"的数据项？').then(function() {
        return delExamRecordSpecial(examRecordIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('examination/examRecordSpecial/export', {
        ...this.queryParams
      }, `examRecordSpecial_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
